package me.cxlr.qinlauncher2.view.settings;

import android.os.Bundle;

import androidx.navigation.fragment.NavHostFragment;
import androidx.preference.DropDownPreference;
import androidx.preference.PreferenceFragmentCompat;

import me.cxlr.qinlauncher2.R;
import me.cxlr.qinlauncher2.util.ThemeUtil;

/**
 * 桌面按键设置
 *
 * @author 酷安用户:山轮纸
 */
public class KeySettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.preferences_key_settings, rootKey);

        // 桌面设置->数字键单击设置
        DropDownPreference numberKeySettings = findPreference("number_key_settings");
        assert numberKeySettings != null;
        numberKeySettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(KeySettingsFragment.this).navigate(R.id.action_keySettingsFragment_to_numberKeySettingsFragment);
            return true;
        });

        // 桌面设置->数字键长按设置
        DropDownPreference numberKeyLongSettings = findPreference("number_key_long_settings");
        assert numberKeyLongSettings != null;
        numberKeyLongSettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(KeySettingsFragment.this).navigate(R.id.action_keySettingsFragment_to_numberKeyLongSettingsFragment);
            return true;
        });

        // 桌面设置->方向键设置
        DropDownPreference dpadKeySettings = findPreference("dpad_key_settings");
        assert dpadKeySettings != null;
        dpadKeySettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(KeySettingsFragment.this).navigate(R.id.action_keySettingsFragment_to_dpadKeySettingsFragment);
            return true;
        });

        // 桌面设置->左右功能键设置
        DropDownPreference functionKeySettings = findPreference("function_key_settings");
        assert functionKeySettings != null;
        functionKeySettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(KeySettingsFragment.this).navigate(R.id.action_keySettingsFragment_to_functionKeySettingsFragment);
            return true;
        });

        // 桌面设置->其他按键
        DropDownPreference combinationKeySettings = findPreference("other_key_settings");
        assert combinationKeySettings != null;
        combinationKeySettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(KeySettingsFragment.this).navigate(R.id.action_keySettingsFragment_to_otherKeySettingsFragment);
            return true;
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        ThemeUtil.initTheme();
    }
}